<template>
  <div>
    <el-form ref="refFormLogin" :model="FormLoginVO" :rules="FormLoginVO_Rules" auto-complete="on" label-position="left">
      <el-row>
        <!-- <el-row class="gl_mt_20">
          <el-col align="left" class="gl_my_20">
            <span class="title">
              {{ $t('login.title') }}
            </span>
          </el-col>
        </el-row> -->
        <el-col>
          <span class="new_title">账户密码登录</span>
        </el-col>
        <!-- <el-col :span="12" align="right">
          <el-button type="text" @click="routerRedirect">{{ $t('login.noAccount') }} {{ $t('login.createAccount') }}</el-button>
        </el-col> -->
      </el-row>
      <el-form-item prop="userNameOrEmailAddress">
        <span class="svg-container">
          <svg-icon icon-class="user" />
        </span>
        <el-input v-model.trim="FormLoginVO.userNameOrEmailAddress" :placeholder="$t('login.username')" name="userNameOrEmailAddress" type="text" tabindex="1" />
      </el-form-item>
      <el-form-item prop="password">
        <span class="svg-container">
          <svg-icon icon-class="password" />
        </span>
        <el-input ref="password" :key="passwordType" v-model.trim="FormLoginVO.password" :type="passwordType" :placeholder="$t('login.password')" name="password" tabindex="2" @keyup.enter.native="$emit(clickLogin)" />
        <span class="show-pwd" @click="showPwd">
          <svg-icon :icon-class="passwordType === 'password' ? 'eye' : 'eye-open'" />
        </span>
      </el-form-item>
      <slot name="EXTENDFORM" />
    </el-form>
    <slot name="FORMLOGIN" />
    <div v-if="platform !== 'hall'" class="register">
      <div class="other" style="visibility: hidden;">
        <span>{{ $t('login.otherLoginType') }}</span>
        <img class="wechat" src="@/assets/images/weChat.svg" alt="">
      </div>
      <div class="regis">
        <el-button type="text" @click="routerRedirect">{{ $t('login.createAccount') }}</el-button>
      </div>
    </div>
  </div>
</template>

<script>
import { mapState, mapActions } from 'vuex';
import { FormLoginVO_Rules } from '@/lib/validate/login/index.js';
import { FormLoginVO } from '@/lib/form/login';

export default {
  name: 'FormLogin',
  props: {
    platform: {
      type: String,
      default: ''
    }
  },
  data() {
    return {
      FormLoginVO_Rules: new FormLoginVO_Rules(),
      FormLoginVO: new FormLoginVO(),
      passwordType: 'password'
    };
  },
  computed: {
    ...mapState({
      markTelephone: state => state.app.markTelephone
    })
  },
  created() {
    this.FormLoginVO.userNameOrEmailAddress = this.markTelephone;
  },
  methods: {
    ...mapActions({ setMarkTelephone: 'app/setMarkTelephone' }),
    showPwd() {
      if (this.passwordType === 'password') {
        this.passwordType = '';
      } else {
        this.passwordType = 'password';
      }
      this.$nextTick(() => {
        this.$refs.password.focus();
      });
    },
    getOtherQuery(query) {
      return Object.keys(query).reduce((acc, cur) => {
        if (cur !== 'redirect') {
          acc[cur] = query[cur];
        }
        return acc;
      }, {});
    },
    routerRedirect() {
      this.setMarkTelephone(this.FormLoginVO.userNameOrEmailAddress);
      this.$router.push({
        name: 'register',
        query: {
          ReturnUrl: this.$route.query['ReturnUrl']
        },
        params: this.$route.params
      });
    }
  }
};
</script>
<style lang="scss" scoped>
.register {
  color: #073190;
  line-height: 22px;
  width: 100%;
  height: 22px;
  font-size: 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 10px;
  .other {
    display: inline-block;
    width: 308px;
    text-align: left;
    color: rgba(0,0,0,0.65);
    line-height: 22px;
    .wechat{
      width: 24px;
      height: 24px;
      margin-left: 15px;
      display: inline-block;
      vertical-align: middle;
      cursor: pointer;
      background-color: #C0C2C5;
      border-radius: 12px;
    }
    .wechat:hover {
      background-color: #19D100
    }
  }
  .regis {
    display: inline-block;
    // width: 60px;
  }
}
.new_title {
  display: block;
  border-bottom: 2px solid #073190;
  color: #073190;
  font-size: 16px;
  width: 136px;
  height: 40px;
  line-height: 40px;
  text-align: center;
  margin: 24px auto;
}
</style>
